<include file="Common/header" />
<!-- 导航栏 -->
{$bread_crumb}
<!-- 导航栏 -->
<div class="page-container">
    <!-- 操作 -->
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <!-- <a href="javascript:;" onclick="del_select()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>  -->
            <a class="btn btn-primary radius" onclick="add('添加','{:U(CONTROLLER_NAME.'/add')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
        </span> 
        <span class="r">共有数据：<strong>{$count}</strong> 条</span> 
    </div>
    <div class="mt-20 dataTables_wrapper">
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
            <tr class="text-c">
                <th>ID</th>
                <th>链接</th>
                <th>图片</th>
                <th>是否显示</th>
                <th>时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <foreach name="banner" item="item">
                <tr class="text-c">
                    <td>{$item['id']}</td>
                    <td style="text-align: left;" width="15%">{$item['url']}</td>
                    <td><img width="60" class="round" src="{$item['image']}"></td>
                    <td>{$item['is_show']}</td>
                    <td>{$item['add_time']}</td>
                    <td class="td-manage" width="15%">
                        <a style="text-decoration:none" class="ml-5" onClick="update('编辑','{:U(CONTROLLER_NAME.'/update')}','{$item['id']}')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>

                        <a style="text-decoration:none" class="ml-5" onClick="del(this,'{$item['id']}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
            </foreach>
        </tbody>
    </table>
    {$pages}
</div>
<include file="Common/footer" />
<script type="text/javascript">
/*添加*/
function add(title,url){
    var index = layer.open({
        type: 2,
        title: title,
        content: url,
        end:function () {
            window.location.reload();
        }
    });
    layer.full(index);
}
/*编辑*/
function update(title,url,id){
    var index = layer.open({
        type: 2,
        title: title,
        content: url + '?id=' + id
    });
    layer.full(index);
}
/*删除*/
function del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '{:U(CONTROLLER_NAME.'/delete')}',
            data: {id: id},
            dataType: 'json',
            success: function(data){
                if (data.code == 0) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                } else {
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            },
            error: function(data) {
                console.log(data.msg);
            },
        });     
    });
}
/*删除所选*/
function del_select() {
    var arr = []
        ids = '';
    $('.select:checkbox:checked').each(function() {
        arr.push($(this).val());
    });

    ids = arr.join(',');
    layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '{:U(CONTROLLER_NAME.'/delete')}',
            data: {id: ids},
            dataType: 'json',
            success: function(data){
                if (data.code == 0) {
                    layer.msg('已删除!',{icon:1,time:1000});
                    window.location.reload();
                } else {
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            },
            error: function(data) {
                console.log(data.msg);
            },
        });
    });
}
// 查看下级分类
function getChilds(obj, parent_id) {
    $.ajax({
        type: 'POST',
        url: '{:U(CONTROLLER_NAME.'/getChilds')}',
        data: {parent_id: parent_id},
        dataType: 'json',
        success: function(data){
            if (data.data == null) {
                layer.msg('该分类下没有二级分类',{icon:2,time:1000});
            } else {
                for (var i = data.data.length -1 ; i >= 0; i--) {
                    var html = '<tr class="text-c">'
                    + '<td style="text-align: left;"> &nbsp;&nbsp;| -- ' + data.data[i].name + '</td>'
                    + '<td><img width="60" class="round" src="' + data.data[i].image + '"></td>'
                    + '<td>' + data.data[i].sort + '</td>'
                    + '<td>' + data.data[i].description + '</td>'
                    + '<td>' 
                    +'<a style="text-decoration:none" class="ml-5" onClick="update(\'编辑\',\'{:U(CONTROLLER_NAME.'/update')}\', ' + data.data[i].id + ')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>'
                    + '<a style="text-decoration:none" class="ml-5" onClick="del(this, ' + data.data[i].id + ')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>'
                    + '</tr>';
                    $(obj).parent().parent().after(html);
                }
                /*$(obj).parents("tr").find(".td-manage").prepend('<a href="javascript:;" title="已加载分类" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');*/
                $(obj).remove();
            }
        },
        error: function(data) {
            console.log(data.msg);
        },
    });
}
</script> 